home *** CD-ROM | disk | FTP | other *** search
- /* main.c -- main routine for Status and Status-Who sample service daemons.
- *
- * Author: Chris Jalbert
- * Copyright 1996 Apple Computer, Inc.
- * All Rights Reserved.
- *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF APPLE COMPUTER, INC.
- * The copyright notice above does not evidence any actual or
- * intended publication of such source code.
- *
- * History:
- * 8/19/96 Chris Jalbert
- * Initial check in of new sample.
- * 1/3/96 Chris Jalbert
- * Added code to test new AIX library function, PPCGetSelectMask.
- */
-
-
- /* A lot of the following stuff works only when _ALL_SOURCE is defined
- * because it is only available on BSD compatable systems.
- */
-
- #ifdef _AIX
- # ifndef _ALL_SOURCE
- # define _ALL_SOURCE
- # define USING_ALL_SOURCE
- # endif /* _ALL_SOURCE */
-
- # include <sys/select.h> /* required for fd_set and select() */
- # include <stdio.h> /* required for _P_tmpdir */
- # include <time.h> /* required for struct timeval */
-
- # ifdef USING_ALL_SOURCE
- # undef _ALL_SOURCE
- # undef USING_ALL_SOURCE
- # endif /* USING_ALL_SOURCE */
- #else /* _AIX */
- # define _P_tmpdir "Desktop"
- #endif /* _AIX */
-
-
- /* It doesn't really matter at this point, but the rest can be compiled
- * as strict POSIX or X/OPEN.
- */
- #include <stdlib.h>
- #include <unistd.h> /* required for chdir() */
-
- /* MacOS header files. */
- #include <Types.h>
- #include <AppleEvents.h>
-
- extern int WaitNextAppleEvent (EventRecord *, long *) ;
-
- #include "tridentd.h"
- #include "debug.h"
-
-
- /******************************************************************************
- ==> Globals <==
- ******************************************************************************/
- Boolean TimeToQuit = false ;
-
- #if _DEBUG
- FILE *__DebugFile ;
- #endif
-
-
- /******************************************************************************
- ==> Global Functions <==
- ******************************************************************************/
- #ifndef _AIX
- int WaitNextAppleEvent (
- EventRecord *event,
- long *lTimeOut)
- {
- WaitNextEvent (highLevelEventMask, event, (60 * *lTimeOut), NULL) ;
- switch (event->what)
- {
- case nullEvent:
- /* Might need to do some processing here. */
- return 0 ;
- case kHighLevelEvent:
- return 1 ;
- }
- return 0 ;
- }
- #endif /* _AIX */
-
-
- /******************************************************************************
- ==> Main Function <==
- ******************************************************************************/
- void main (
- int argc,
- char **argv)
- {
- OSErr result ;
-
- chdir (_P_tmpdir) ; /* so core files end up in /tmp */
-
- DBGSetup ((SIMPLIFIED ? "/tmp/simpled.debug" : "/tmp/flexibled.debug")) ;
- DBGM ("Sleeping 15 seconds to allow dbx to attach...\n") ;
- DBGPause (15) ;
- DBGM ("Starting initialization procedures.\n") ;
-
- /* Install Apple event handlers. */
- if (result = InitAEStuff (0L))
- {
- DBG ("Error %d during InitAEStuff().\n", result) ;
- exit (result) ;
- }
-
- /*** Stub or delete this call for simplified service daemons!! ***/
- /* Register services with PPC Toolbox. */
- if (result = InitPPCStuff ())
- {
- DBG ("Error %d during InitPPCStuff().\n", result) ;
- exit (result) ;
- }
-
- InitApp () ;
-
- while (!TimeToQuit && (result >= 0))
- {
- long lTimeOut ;
- EventRecord event ;
-
- /*** Stub or delete this call for simplified service daemons!! ***/
- /* Give the Mac OS version some time to deal with PPC overhead. */
- result = PPCTimeSlice () ;
-
- /* Update the timers in the list of connections. */
- lTimeOut = UpdateClients () ;
-
- DBG ("main(): setting timeout of %ld seconds.\n", lTimeOut) ;
-
- #if defined(_AIX) && !SIMPLIFIED
- {
- extern Boolean GetMySelectMask (fd_set *) ;
- fd_set fdsMask ;
- struct timeval tsTimeout = { 0, 0 } ;
-
- PPCGetSelectMask (&fdsMask) ;
- tsTimeout.tv_sec = lTimeOut ;
- if (GetMySelectMask (&fdsMask))
- {
- DBGM ("main(): Making select call manually.\n") ;
- select (FD_SETSIZE, &fdsMask, 0, 0, &tsTimeout) ;
- }
- }
- #endif /* _AIX */
-
- /* Wait for an Apple Event or a new connection. */
- if (0 < (result = WaitNextAppleEvent (&event, &lTimeOut)))
- {
- result = AEProcessAppleEvent (&event) ;
- DBG ("main(): AEProcessAppleEvent() returned (%d)\n", result) ;
- }
- }
-
- /*** Stub or delete this call for simplified service daemons!! ***/
- PPCShutDown () ;
- DBGClose () ;
- exit (0) ;
- }
-